jQuery(function($) {
	
	/*var setting = {
		view: {
			selectedMulti: false
		},
		edit: {
			enable: true,
			showRemoveBtn: false,
			showRenameBtn: false
		},
		data: {
			keep: {
				parent:true,
				leaf:true
			},
			simpleData: {
				enable: true
			}
		},		
	};*/
	
	var setting = {
		data: {
		  simpleData: {
			enable:true,
			idKey: "id",
			pIdKey: "pId",
			//click:true,
			rootPId: ""
          }
		},
		callback: {
			//beforeClick: zTreeOnClick2,
			onClick: zTreeOnClick,	
		}
	};		
		$.ajax({
			type:"post",
			url:"index.php?r=merchandis/ztree",
			dataType:"json",
			success:function(msg){				
		     $.fn.zTree.init($("#treeDemo"), setting,msg);				
			},
			error: function (msg) {  
                alert("失败");  
            }
							
		});
		
		//获取类的PID并传递到添加类别控制器
		
		/*function zTreeOnClick2(event, treeId, treeNode) {
		    //alert(treeNode.tId + ", " + treeNode.name);			     
			 id = treeNode.id;	
			
			 $.ajax({				
					type:"post",
					url:"index.php?r=merchandis/id",				
					dataType:"html",				
					data:{
						 "action":"Aadd_action",
					     "id":id								
					},
					success:function(msg){
						$("#home4").empty().show().append(msg);
					}						
				});			
		}*/
		
		
	function zTreeOnClick(event, treeId, treeNode) {
		    //alert(treeNode.tId + ", " + treeNode.name);			     
			 id = treeNode.id;	
			
			 $.ajax({				
					type:"post",
					url:"index.php?r=merchandis/modify",				
					//dataType:"html",				
					data:{
						 "action":"modify_action",
					     "id":id								
					},
					success:function(msg){
						$("#profile4").empty();
						$("#profile4").html(msg);
					}			
				});	
			 		 
			 $.ajax({				
					type:"post",
					url:"index.php?r=merchandis/id",				
					//dataType:"html",				
					data:{
						 "action":"Aadd_action",
					     "id":id								
					},
					success:function(msg){
						$("#home4").empty();
						$("#home4").html(msg);
					}			
				});
			 
			 $.ajax({				
					type:"post",
					url:"index.php?r=merchandis/dele",				
					//dataType:"html",				
					data:{
						 "action":"delet_action",
					     "id":id								
					},
					success:function(msg){
						$("#dropdown14").empty();
						$("#dropdown14").html(msg);
					}			
				});
			 			 
		}
		
	
	
		/*var setting = {
			callback: {
				onClick: zTreeOnClick
			}
		};*/
				
		//执行click事件并ztree点击事件
		var log, className = "dark";
		function beforeClick(treeId, treeNode, clickFlag) {
			className = (className === "dark" ? "":"dark");
			showLog("[ "+getTime()+" beforeClick ]&nbsp;&nbsp;" + treeNode.name );
			
			return (treeNode.click != false);
		}
		function onClick(event, treeId, treeNode, clickFlag) {
			showLog("[ "+getTime()+" onClick ]&nbsp;&nbsp;clickFlag = " + clickFlag + " (" + (clickFlag===1 ? "普通选中": (clickFlag===0 ? "<b>取消选中</b>" : "<b>追加选中</b>")) + ")");
			
		}		
		function showLog(str) {
			if (!log) log = $("#log");
			log.append("<li class='"+className+"'>"+str+"</li>");
			if(log.children("li").length > 8) {
				log.get(0).removeChild(log.children("li")[0]);
			}
		}
		function getTime() {
			var now= new Date(),
			h=now.getHours(),
			m=now.getMinutes(),
			s=now.getSeconds();
			return (h+":"+m+":"+s);
		}
				
//-->
})